//
//  Status.swift
//  weibo1
//
//  Created by changhongliang on 2017/7/26.
//  Copyright © 2017年 richinfo. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    ///微博创建时间
    var created_at:String?
    /// 微博消息内容
    var text:String?
    ///微博来源
    var source:String?
    /// 字符串型的微博ID
    var idstr: String?
    ///转发数
    var reposts_count = -1
    ///评论数
    var comments_count = -1
    ///点赞数
    var attitudes_count = -1
    ///当前微博对应的用户
    var user: User?
    
    /// 存储所有配图
    var pic_urls: [[String: AnyObject]]?
    /// 转发微博
    var retweeted_status: Status?
    
    init(dict:[String:AnyObject]){
        super.init()
        setValuesForKeys(dict)
    }
    
    ///swift中如果遇到模型中套模型就这样处理
    ///1.创建子模型
    ///2.重写 func setValue(_ value: Any?, forKey key: String)这个方法
    ///3.对于这个特殊的key,自己处理.其余情况调supper 处理
    override func setValue(_ value: Any?, forKey key: String) {
        if key == "user" {
            user = User(dict:value as![String:AnyObject])
            return
        }
        if key == "retweeted_status" {
            retweeted_status = Status(dict: value as! [String: AnyObject])
            return
        }
        
        super.setValue(value, forKey: key)
        
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    
    override var description: String {
        let property = ["created_at","text","source","reposts_count","comments_count","attitudes_count","user","pic_urls"]
        let dic = dictionaryWithValues(forKeys: property)
        return "\(dic)"
    }
    
    
    

}
